/**
 * Created With IntelliJ IDEA
 * Description:leetcode：189. 轮转数组
 * <a href="https://leetcode.cn/problems/rotate-array/">...</a>
 * User: DELL
 * Data: 2022-12-02
 * Time: 13:55
 */
class Solution {

    public void reverse (int[] nums,int begin,int end) {
        if (begin < 0 || end >= nums.length) {
            return;
        }
        while (begin < end) {
            int tmp = nums[begin];
            nums[begin] = nums[end];
            nums[end] = tmp;
            begin++;
            end--;
        }
        return;
    }
    //将数组逆序三次即可
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        //避免k大于len而导致无效逆转
        k %= len;
        reverse(nums,0,len-1);
        reverse(nums,0,k -1);
        reverse(nums,k,len-1);
        return;
    }
}